@extends('layouts.app')
@include('template.sidebar')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <a class="btn btn-success" href="{{ route('admin.template.create', ['type' => $type]) }}">添加</a>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>id</th>
                    <th>场景</th>
                    <th>模板ID</th>
                    <th>状态</th>
                    <th>操作</th>
                    <th>排序权重</th>
                </tr>
                </thead>
                <tbody>
                @php $num = 1; @endphp
                @foreach($templates as $item)
                    <tr>
                        <td>{{ $num }}</td>
                        <td>{!! $item->scene !!}</td>
                        <td>{!! $item->template_id !!}</td>
                        <td>
                            @if($item->status == 1)
                                开启
                            @else
                                关闭
                            @endif
                        </td>
                        <td>
                            @can("template-edit")
                                <a class="btn btn-primary btn-xs"
                                   href="{{ route('admin.template.edit', ['id' => $item->id]) }}"><i
                                        class="fa fa-edit"></i> 编辑</a>
                            @endcan
                            @can('template_on_off')
                                @if($item->status == 0)
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.template.status', ['id' => $item->id]) }}"><i class="fa fa-circle-o-notch"></i> 开启</a>
                                @else
                                    <a class="btn btn-danger btn-xs" href="{{ route('admin.template.status', ['id' => $item->id]) }}"><i class="fa fa-ban"></i> 关闭</a>
                                @endif
                            @endcan
                        </td>
                        <td>
                            <input type="text" class="col-xs-3 change-sort" data-id="{{ $item->id }}"
                                   value="{{ $item->sort }}"/>
                        </td>
                    </tr>
                    @php $num++; @endphp
                @endforeach

                </tbody>
            </table>

        </div>
    </div>
@endsection
@push('stylesheets')

@endpush
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.template.sort') }}',
                type: "GET",
                dataType:'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });
    </script>
@endpush



